package com.ainge.jwt.jwe;


/**
 * BASE64URL(UTF8(JWE Protected Header)) || '.' ||
 * BASE64URL(JWE Encrypted Key) || '.' ||
 * BASE64URL(JWE Initialization Vector) || '.' ||
 * BASE64URL(JWE Ciphertext) || '.' ||
 * BASE64URL(JWE Authentication Tag)
 * <p>
 * <p>
 * Created by Ainge on 2019/11/24
 */
public class JweCompactObject {

    /**
     * header 里面是一个JSON字符串
     */
    private String jweHeaders;

    /**
     * AES的对称密钥，用于解密
     */
    private String encryptedKey;

    /**
     * IV向量，用于解密
     */
    private String iv;

    /**
     * 密文，真正传输的数据
     */
    private String ciphertext;

    /**
     * Authentication Tag 用于验证
     */
    private String authTag;

    public JweCompactObject(String compactSerialization) {

        if (compactSerialization == null || compactSerialization.trim().isEmpty()) {
            throw new IllegalArgumentException("compactSerialization");
        }
        String[] deserialize = CompactSerializer.deserialize(compactSerialization);
        if (deserialize.length != 5) {
            throw new IllegalArgumentException("JweCompactObject deserialize error ...");
        }
        this.jweHeaders = deserialize[0];
        this.encryptedKey = deserialize[1];
        this.iv = deserialize[2];
        this.ciphertext = deserialize[3];
        this.authTag = deserialize[4];
    }


    public String getJweHeaders() {
        return jweHeaders;
    }

    public String getEncryptedKey() {
        return encryptedKey;
    }


    public String getIv() {
        return iv;
    }

    public String getCiphertext() {
        return ciphertext;
    }

    public String getAuthTag() {
        return authTag;
    }

}
